package logic

import (
	"Junior_two/subject/goods/goodsrpc/model"
	"context"
	"encoding/json"
	"fmt"
	"net/http"

	"Junior_two/subject/goods/goodsrpc/internal/svc"
	"Junior_two/subject/goods/goodsrpc/pb/goodRpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsDescLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodsDescLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsDescLogic {
	return &GoodsDescLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodsDescLogic) GoodsDesc(in *goodRpc.DescRequest) (*goodRpc.DescResponse, error) {
	// todo: add your logic here and delete this line
	g, err := model.Desc(in.Id)
	fmt.Println(g)
	if err != nil {
		return &goodRpc.DescResponse{
			Msg:  "查看失败",
			Code: http.StatusAccepted,
		}, nil
	}
	jsG, _ := json.Marshal(g)
	fmt.Println(string(jsG))
	return &goodRpc.DescResponse{
		Msg:  "查看详情成功",
		Code: http.StatusOK,
		Data: string(jsG),
	}, nil
}
